package cn.wolfcode.rbac.web.intercptor;

import cn.wolfcode.rbac.domain.Employee;
import cn.wolfcode.rbac.util.UserContext;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Administrator on 2020/7/13 0013.
 */
public class CheckLoginIntercptor implements HandlerInterceptor {
    /**
     * 前置拦截方法
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //1 上Session中去取值, 看是否有employee对象  , 如果有说明之前登陆了放行
        // 如果没有说明之前没有登录, 那么进行拦截, 并且让他跳转到登录界面
        Employee employee = UserContext.getCurrent();
        if (employee == null){
            response.sendRedirect("/login.jsp");
            return false;
        }
        //放行
        return true;
    }
}
